//
//  BaseViewController.swift
//  weibo
//
//  Created by 叶子韬韬 on 2017/4/20.
//  Copyright © 2017年 叶子韬韬. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    // MARK:- #注释>定义变量  记录是否登录
    var isLogin:Bool = false
    internal lazy var visitorView:VisitorView = VisitorView.visitorView()
    override func loadView() {
        
        //检测本地是否登录过
        isLogin = UserAccoutViewModel.shareInstance.isLogin
        //判断要加载view
        isLogin ? super.loadView() :setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupNavigationItems()
    }


}

extension BaseViewController{
    // MARK:- #注释> 设置访客视图
    internal func setupVisitorView(){
        view = visitorView
        
        visitorView.registBtn.addTarget(self, action: #selector(BaseViewController.registerBtnClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewController.loginBtnClick), for: .touchUpInside)
    }
    
    func setupNavigationItems() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.loginBtnClick))
        
    }
}

// MARK:- #注释>事件监听
extension BaseViewController{
    internal func registerBtnClick(){
       print("registerBtnClick")
    }
    internal func loginBtnClick(){
        
        let oauth : OAuthViewController = OAuthViewController()
        
        //包装一个导航控制器
        let oauthNav = UINavigationController(rootViewController: oauth)
        
        present(oauthNav, animated: true, completion: nil)
        
    }
}

